<script setup>
import {ref} from "vue";

const showNotification = ref(false)
const notificationMessage = ref('')
const notificationType = ref('success')

const showNotificationMessage = (message, type) => {
  notificationMessage.value = message
  notificationType.value = type
  showNotification.value = true

  // 3秒后自动隐藏
  setTimeout(() => {
    showNotification.value = false
  }, 3000)
}

defineExpose({showNotificationMessage})
</script>

<template>
  <transition name="notification">
    <div v-if="showNotification" class="notification" :class="notificationType">
      <span>{{ notificationMessage }}</span>
      <button @click="showNotification = false">×</button>
    </div>
  </transition>
</template>

<style scoped>
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 15px 20px;
  border-radius: 10px;
  color: white;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  animation: slideInRight 0.3s ease-out;
}

.notification.success {
  background: #4CAF50;
}

.notification.error {
  background: #F44336;
}

.notification button {
  background: none;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.notification-enter-active,
.notification-leave-active {
  transition: all 0.3s ease;
}

.notification-enter-from,
.notification-leave-to {
  opacity: 0;
  transform: translateX(100%);
}
</style>